package com.ruoyi.web.controller.decision;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.decision.domain.TemplatePlan;
import com.ruoyi.decision.service.ITemplatePlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 预案库Controller
 * 
 * @author zbw
 * @date 2022-07-20
 */
@RestController
@RequestMapping("/decision/templateplan")
public class TemplatePlanController extends BaseController
{
    @Autowired
    private ITemplatePlanService templatePlanService;

    /**
     * 查询预案库列表
     */
    @PreAuthorize("@ss.hasPermi('decision:templateplan:list')")
    @GetMapping("/list")
    public TableDataInfo list(TemplatePlan templatePlan)
    {
        startPage();
        List<TemplatePlan> list = templatePlanService.selectTemplatePlanList(templatePlan);
        return getDataTable(list);
    }

    /**
     * 导出预案库列表
     */
    @PreAuthorize("@ss.hasPermi('decision:templateplan:export')")
    @Log(title = "预案库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TemplatePlan templatePlan)
    {
        List<TemplatePlan> list = templatePlanService.selectTemplatePlanList(templatePlan);
        ExcelUtil<TemplatePlan> util = new ExcelUtil<TemplatePlan>(TemplatePlan.class);
        util.exportExcel(response, list, "预案库数据");
    }

    /**
     * 获取预案库详细信息
     */
    @PreAuthorize("@ss.hasPermi('decision:templateplan:query')")
    @GetMapping(value = "/{templateId}")
    public AjaxResult getInfo(@PathVariable("templateId") String templateId)
    {
        return AjaxResult.success(templatePlanService.selectTemplatePlanByTemplateId(templateId));
    }

    /**
     * 新增预案库
     */
    @PreAuthorize("@ss.hasPermi('decision:templateplan:add')")
    @Log(title = "预案库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TemplatePlan templatePlan)
    {
        return toAjax(templatePlanService.insertTemplatePlan(templatePlan));
    }

    /**
     * 修改预案库
     */
    @PreAuthorize("@ss.hasPermi('decision:templateplan:edit')")
    @Log(title = "预案库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TemplatePlan templatePlan)
    {
        return toAjax(templatePlanService.updateTemplatePlan(templatePlan));
    }

    /**
     * 删除预案库
     */
    @PreAuthorize("@ss.hasPermi('decision:templateplan:remove')")
    @Log(title = "预案库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{templateIds}")
    public AjaxResult remove(@PathVariable String[] templateIds)
    {
        return toAjax(templatePlanService.deleteTemplatePlanByTemplateIds(templateIds));
    }
}
